home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 98 / Skunkware 98.iso / src / mail / pine3.96.tar.gz / pine3.96.tar / pine3.96 / pine / osdep / execview.os2 < prev    next >
Text File  |  1996-04-25  |  2KB  |  110 lines

  1. #line 2 "osdep/execview.os2"
  2. /*----------------------------------------------------------------------
  3.     Routine to execute command mailcap says is used to display MIME segment
  4.     under OS/2
  5.  
  6.  The exported routine is:
  7.  
  8.     exec_viewer -- 
  9.  
  10.  ----*/
  11.  
  12. #include    <process.h>
  13.  
  14.  
  15. /* ----------------------------------------------------------------------
  16.    Execute the given 
  17.  
  18.   Args: cmd -- 
  19.     image_file --
  20.   
  21.      
  22.   ----*/
  23. void
  24. exec_mailcap_cmd(cmd, image_file, needsterminal)
  25.     char *cmd;
  26.     char *image_file;
  27.     int   needsterminal;  /* not used in DOS */
  28. {
  29.     int   rc;
  30.  
  31.     cancel_busy_alarm(1);
  32.     interrupt_ok();
  33.     rc = system(cmd);
  34.     dont_interrupt();
  35.  
  36.     if(rc < 0)
  37.       q_status_message1(SM_ORDER, 3, 4, "Failed to exec viewer: %s",
  38.             (errno == E2BIG) ? "Argument list too big" :
  39.               (errno == ENOENT) ? "No command interpreter" :
  40.                 (errno == ENOMEM) ? "Not enough memory"
  41.                 : "Unknown Error");
  42.     unlink(image_file);
  43. }
  44.  
  45.  
  46. /* ----------------------------------------------------------------------
  47.    Execute the given test= cmd
  48.  
  49.   Args: cmd -- command to execute
  50.   Returns exit status
  51.      
  52.   ----*/
  53. int
  54. exec_mailcap_test_cmd(cmd)
  55.     char *cmd;
  56. {
  57. #define    MAXARGS    10
  58.     char *args[MAXARGS], *cp;
  59.     int   i, rv;
  60.  
  61.     cp = cmd;
  62.  
  63.     /* build args */
  64.     for(i=0; *cp != '\0'; i++){            /* build args array */
  65.     if(i < MAXARGS+2){
  66.         args[i] = NULL;            /* in case we break out */
  67.     }
  68.     else{
  69.         q_status_message1(SM_ORDER | SM_DING, 3, 5,
  70.                   "Too many args : %s",
  71.                   ps_global->VAR_IMAGE_VIEWER);
  72.         return -1;
  73.     }
  74.  
  75.     while(isspace((unsigned char)(*cp)))
  76.       if(*cp != '\0')
  77.         cp++;
  78.       else
  79.         break;
  80.  
  81.     args[i] = cp;
  82.  
  83.     while(!isspace((unsigned char)(*cp)))
  84.       if(*cp != '\0')
  85.         cp++;
  86.       else
  87.         break;
  88.  
  89.     if(*cp != '\0')
  90.       *cp++ = '\0';
  91.     }
  92.     args[i] = NULL;
  93.  
  94.     /* actually display the sucker */
  95.     interrupt_ok();
  96.     rv = spawnvp(P_WAIT, args[0], args);
  97.     dont_interrupt();
  98.     if(rv == -1) {
  99.     /* error spawning image viewer */
  100.         q_status_message2(SM_ORDER | SM_DING, 4, 5, "Error \"%s\" spawning %s",
  101.                           error_description(errno),
  102.               ps_global->VAR_IMAGE_VIEWER); 
  103.     return -1;
  104.     }
  105.  
  106.     return(rv);
  107. }
  108.  
  109.  
  110.